﻿
#include <iostream>
#include <ostream>
#include <istream>
#include <sstream>
#include "serialize.hpp"

struct Rect_t
{
    uint32_t x = 0;
    uint32_t y = 0;
    uint32_t w = 0;
    uint32_t h = 0;
};

struct BBox_t
{
    std::vector<Rect_t> rects;
    uint32_t index = 0;
};

int main()
{
    std::cout << "__cplusplus: " << __cplusplus << std::endl;
    std::vector<BBox_t> bboxs;
    for (size_t j = 0; j < 10; j++)
    {
        BBox_t bbox;
        for (size_t i = 0; i < 2; i++)
        {
            Rect_t rect;
            rect.x = i + 100;
            rect.y = i + 200;
            rect.w = i + 300;
            rect.h = i + 400;
            bbox.rects.push_back(rect);
        }
        bbox.index = j;
        bboxs.push_back(bbox);
    }

    std::ostringstream ss;
    for(auto& bbox: bboxs) 
    {
        serialize(ss, bbox.rects);
        serialize(ss, bbox.index);
    }
    std::cout << ss.str() << std::endl;
    std::istringstream is(ss.str());

    uint32_t strLen = is.str().length();
    while (!is.eof() && is.tellg() != strLen)
    {
        BBox_t bbox;
        deserialize(is, bbox.rects);
        deserialize(is, bbox.index);
        std::cout << "bbox.index: " << bbox.index << std::endl;
    }
}
